package com.chexiehui.jc.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;

import com.aries.ui.view.radius.RadiusTextView;
import com.blankj.utilcode.util.StringUtils;
import com.chexiehui.jc.R;
import com.chexiehui.jc.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class InputUsernameActivity extends BaseActivity {

    @BindView(R.id.et_text)
    EditText etText;
    @BindView(R.id.rtv_submit)
    RadiusTextView rtvSubmit;
    private String oldText;

    @Override
    protected void beforeSetView() {
        Bundle bundle = getIntent().getExtras();
        if(bundle != null){
            oldText = bundle.getString("oldText");
        }
        if(oldText == null){
            oldText = "";
        }
    }

    @Override
    protected void setTitleBar() {
        titleBar.setTitleMainText("修改用户名");
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_input_username;
    }

    @Override
    protected void initView(Bundle var1) {
        etText.setText(oldText);
        etText.setSelection(etText.getText().length());
    }

    @OnClick(R.id.rtv_submit)
    public void onViewClicked() {
        if(StringUtils.isTrimEmpty(etText.getText().toString().trim())){
            showToast("请输入");
            return;
        }
        if(oldText.equals(etText.getText().toString().trim())){
            showToast("与原值相同");
            return;
        }
        Intent intent = new Intent();
        intent.putExtra("text", etText.getText().toString().trim());
        setResult(RESULT_OK, intent);
        finish();
    }
}
